<template>
  <div class="address-container">
    <appHerder>收货地址</appHerder>
    <div class="center-container" v-if="address.length === 0">
      <div class="center">
        <img src="../assets/2V8DU1CX.jpg" alt="">
        <div class="center-text">无收货地址</div>
      </div>
    </div>
    <div class="center-container" v-if="address.length !== 0">
      <div v-for="(item, key) in address" class="center-address">
        <div class="center--box">
          <div class="news-address">
            <img src="../assets/coordinate.png" alt="" class="center-img">
            <span>{{item.receiver}}</span>
            <span>{{item.phoneNumber}}</span><br>
            <span>{{item.location}}</span>
            <span>{{item.details}}</span>
          </div>
          <div class="assist" :key="key">
            <input id="provision" type="checkbox" class="input">
            <label for="provision" @click="tacitly(key)" class="aa"><span class="bb">设为默认</span></label>
            <span class="add" id="news-add" @click="revise(key)"><span><img src="../assets/aletr.png" alt="">修改</span></span>
            <div class="add" @click="del(key)" ><span><img src="../assets/del.png" alt="">删除</span></div>
          </div>
        </div>
      </div>
    </div>
    <router-link to="/auth/addAddRess"><div class="bottom">新增收货地址</div></router-link>
  </div>
</template>
<script>
import appHerder from '../components/appHeader';
import 'lib-flexible';
  export default {
    name: 'shipping',
    data() {
      return {
        addrid: '',
        address:[],
      }
    },
    components:{
      appHerder,
    },
    created() {
      // this.address.push(this.$route.params.userInfo);
      this.$apis.getaddr()
        .then(data => {
          console.log(data.data.data);
          this.address =  data.data.data;
        })
        .catch(error =>{
          console.log(error)
        });
    },
    methods:{
      del(key) {
        // console.log(this.address[key]["_id"]);
        this.$apis.deleteaddr({params: {addrid: this.address[key]["_id"]}})
          .then(data => {
                if (data.data.code === 1) {
                  this.$toast({
                    message: '删除成功',
                    duration: 800,
                    color: '#fff',
                  })
                }
                this.address.splice(key, 1);
          })
          .catch(error =>{
            console.log(error)
          });
      },
      revise(key) {
        this.$router.push({name: 'reviseAddRess', params: {userInfo: this.address[key]}});
      },
      tacitly(key) {
        this.$apis.defaultAddr({params: {addrid: this.address[key]["_id"]}})
          .then(data => {
            console.log(data);
            console.log(this.address[key]["_id"]);
          })
          .catch(error => {
            console.log(error);
          })
      }
    },
  };
</script>

<style>
  *{
    margin: 0;
    padding: 0;
  }
  .address-container{
    width: 100vw;
    height: 100vh;
  }
  .center-container{
    width: 100vw;
    position: relative;
    top: 1.4rem;
    border-top: 1px solid rgba(0, 0, 0, .2);
  }
  .center{
    position: absolute;
    width: 100vw;
    height: 80vh;
    background: white;
  }
  .center>img{
    width: 6.3rem;
    height: 6rem;
    position:relative;
    left: 50vw;
    top: 30vh;
    transform: translate(-50%, -50%);
  }
  .center-text{
    width: 100vw;
    font-size: 17px;
    text-align: center;
    position: relative;
    top: 10vh;
  }
  .bottom{
    width: 80vw;
    position: fixed;
    bottom: 30px;
    height: 80px;
    line-height: 80px;
    text-align: center;
    background: deepskyblue;
    color: white;
    font-size: 30px;
    left: 9vw;
    border-radius: 5vh;
  }
  #news-add{
    display: inline-block;
    position: relative;
    left: 7.7rem;
  }
  #news-add>span>img{
    display: inline-block;
    width: .37rem;
    position: absolute;
    top: .0001rem;
  }
  .add{
    display: inline-block;
    position: relative;
    top: .3rem;
    left: 8.4rem;
    color: rgba(0,0,0,.7);
  }
  .center-address{
    width: 100vw;
    height: 120px;
  }
  .center-img{
    display: inline-block;
    width: .5rem;
    position: absolute;
    left: -.7rem;
    top: -.1rem;
  }
  .center--box{
    width: 100vw;
    height: 130px;
    border-bottom: 1px solid rgba(160,160,160,.7);
  }
  .news-address{
    position: relative;
    display: inline-block;
    left: .9rem;
    height: 50px;
    font-size: 15px;
    line-height: 20px;
    top: .3rem;
  }
  .news-address>span:nth-child(2){
    display: inline-block;
    position: relative;
    top: -8px;
  }
  .news-address>span:nth-child(3){
    position: absolute;
    display: inline-block;
    width: 2rem;
    left: 6.4rem;
    top: -5px;
  }
  .news-address>span:nth-child(5){
    color: rgba(160,160,160,.8);
    width: 2rem;
    font-size: 20px;
    display: inline-block;
    position: absolute;
  }
  .news-address>span:nth-child(6){
    color: rgba(160,160,160,.8);
    font-size: 20px;
    position: relative;
    display: inline-block;
    left: 2rem;
  }
  .assist{
    position: relative;
    width: 100vw;
    height: 50px;
    top: .3rem;
    border-top: 1px solid rgba(160,160,160,.2);
  }
  .label>label,.input{
    vertical-align:top;
    font-size: .3rem;
  }
  .register{
    position: absolute;
    top: 11rem;
    width: 70%;
    height: 1rem;
    background-color: #3868E4;
    text-align: center;
    line-height: 1rem;
    color: white;
    left: 15%;
    border-radius: 1rem;
    font-size: .45rem;
  }
  #provision{
    display: none;
  }
  .aa{
    display: inline-block;
    width: .3rem;
    height: .3rem;
    border: silver 1px solid;
    border-radius: 50%;
    position: absolute;
    top: .3rem;
    left: .3rem;
  }
  .bb{
    display: inline-block;
    width: 1.5rem;
    vertical-align: middle;
    position: relative;
    left: 35px;
    top: -.2vh;
  }
  input:checked + .aa {
    background: #3c9dfc;
    background-image: url("../assets/checked.png");
    background-size: 16px 16px;
    background-position: center;
  }
  .add>span>img{
    display: inline-block;
    width: .4rem;
    position: absolute;
    left: -.45rem;
    top: -.05rem;
  }
</style>
